home *** CD-ROM | disk | FTP | other *** search
- Path: druid.borland.com!usenet
- From: pete@borland.com (Pete Becker)
- Newsgroups: comp.lang.c
- Subject: Re: Beginer C please help me
- Date: 25 Mar 1996 19:13:23 GMT
- Organization: Borland International
- Message-ID: <4j6r8j$hfm@druid.borland.com>
- References: <4irjqa$jtn@winx03.informatik.uni-wuerzburg.de> <827821769.0snx@n16872.pc.jaring.my>
- NNTP-Posting-Host: pbecker.borland.com
- Mime-Version: 1.0
- Content-Type: Text/Plain; charset=ISO-8859-1
- X-Newsreader: WinVN 0.99.5
-
- In article <827821769.0snx@n16872.pc.jaring.my>, ckyin@n16872.pc.jaring.my
- says...
- >
- >
- > I agree with you completely. What a complete nonsense!
- >
- > In order a get correct answer, should try this:
- >
- > n = 9.0/5 or n = 9/5.0 or n = 9/5*1.0
- >
- > Remember, in C you may not get a floating point answer by division
- > using integer only!
- >
- > I hope this will help!
-
- Unfortunately, two out of three is still bad. n = 9/5*1.0 will assign 1.0 to
- n. Multiplication and division have the same precedence, and they group from
- left to right. This means that the compiler looks first at 9/5, and concludes
- that this is integer arithmethic. Then it looks at *1.0, promotes the result of
- the integer division to double, and performs the multiplication.
- -- Pete
-
-